package net.zabuchy.customer.entity;

import java.io.Serializable;
import javax.persistence.*;

import org.hibernate.annotations.Cascade;

import net.zabuchy.address.entity.Address;
import static javax.persistence.GenerationType.IDENTITY;
import java.util.Date;


/**
 * The persistent class for the customer database table.
 * 
 */
@Entity
@Table(name="customer")
public class Customer implements Serializable {
	private static final long serialVersionUID = 1L;
	private int customerId;
	private Address address;
	private String companyName;
	private Date creationDate;
	private String director;
	private String email;
	private String fax;
	private String phone;
	private LicenceDetail licenceDetail;

    public Customer() {
    }

	public Customer(int customerId, Address address, String companyName,
			Date creationDate, String director, String email, String fax,
			String phone) {
		super();
		this.customerId = customerId;
		this.address = address;
		this.companyName = companyName;
		this.creationDate = creationDate;
		this.director = director;
		this.email = email;
		this.fax = fax;
		this.phone = phone;
	}

	public Customer(Address address, String companyName, Date creationDate,
			String director, String email, String fax, String phone,
			LicenceDetail licenceDetail) {
		super();
		this.address = address;
		this.companyName = companyName;
		this.creationDate = creationDate;
		this.director = director;
		this.email = email;
		this.fax = fax;
		this.phone = phone;
		this.licenceDetail = licenceDetail;
	}
    
    
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name="CUSTOMER_ID")
	public int getCustomerId() {
		return this.customerId;
	}

	public void setCustomerId(int customerId) {
		this.customerId = customerId;
	}


	@ManyToOne(fetch=FetchType.EAGER)
	@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
	@JoinColumn(name="ADDRESS_ID")
	public Address getAddress() {
		return this.address;
	}
	/*@OneToOne(cascade = CascadeType.ALL)
	public Address getAddress() {
		return address;
	}*/

	public void setAddress(Address address) {
		this.address = address;
	}
	/*public void setAddressId(int addressId) {
		this.addressId = addressId;
	}*/


	@Column(name="COMPANY_NAME")
	public String getCompanyName() {
		return this.companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}


    @Temporal( TemporalType.TIMESTAMP)
	@Column(name="CREATION_DATE")
	public Date getCreationDate() {
		return this.creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}


	@Column(name="DIRECTOR")
	public String getDirector() {
		return this.director;
	}

	public void setDirector(String director) {
		this.director = director;
	}


	@Column(name="EMAIL")
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}


	@Column(name="FAX")
	public String getFax() {
		return this.fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	@Column(name="PHONE")
	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}


	@OneToOne(fetch = FetchType.EAGER, mappedBy = "customer", cascade = CascadeType.ALL)
	public LicenceDetail getLicenceDetail() {
		return this.licenceDetail;
	}

	public void setLicenceDetail(LicenceDetail licenceDetail) {
		this.licenceDetail = licenceDetail;
	}

	@Override
	public String toString() {
		return "Customer [customerId=" + customerId + /*", addressId="
				+ address.toString() + */", companyName=" + companyName
				+ ", creationDate=" + creationDate + ", director=" + director
				+ ", email=" + email + ", fax=" + fax + ", phone=" + phone
				+ ", licenceDetail=" + licenceDetail + "]";
	}
	
}